﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.Models;
using PBOffice.BLL;

public partial class ScheduleManager_user : System.Web.UI.Page
{
    List<Branch> branchList = new BranchManager().GetAllBranch();
    List<Department> deptList = new DeptManager().GetAllDepartment();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData(); 
        }
    }
    private void BindData()
    {

        foreach (Branch item in branchList)
        {

            TreeNode tn = new TreeNode(item.BranchShortName);
            tn.Value = item.BranchId.ToString();
            tn.ImageUrl = "~/imges/dept_tree.jpg";
            this.TreeView1.Nodes.Add(tn);
            InitTreeByList(tn);

        }
    }
    private void InitTreeByList(TreeNode TN)
    {
        foreach (Department item in deptList)
        {
            if (item.ParentId.ToString() == TN.Value)
            {
                TreeNode tn = new TreeNode();
                tn.Text = "&nbsp;&nbsp;" + item.DeptName;
                tn.Value = item.DeptId.ToString();
                List<Position> list = new PosManager().GetPosByDept(Convert.ToInt32(item.DeptId));
                if (list.Count != 0)
                {
                    foreach (Position pos in list)
                    {
                        TreeNode t = new TreeNode();
                        t.Text = pos.PosName;
                        t.Value = pos.PosId.ToString();
                        List<Staff> sta = new StaffManager().GetNameByPosIdAndDeptId(item.DeptId, pos.PosId);
                        if (sta.Count != 0)
                        {
                            foreach (Staff aa in sta)
                            {
                                TreeNode s = new TreeNode();
                                s.Text = aa.StfName;
                                s.Value = aa.StfId.ToString();
                                s.ImageUrl = "~/imges/people.jpg";
                                t.ChildNodes.Add(s);
                            }
                        }
                        tn.ChildNodes.Add(t);
                    }
                }
                //tn.NavigateUrl = item.NodeURL;
                // tn.ImageUrl = "~/imges/dept_tree_block.jpg";
                TN.ChildNodes.Add(tn);
                InitTreeByList(tn);
            }


        }
    }
}